package com.lbs.jiepiaisi.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;

/**
 *
 * 时间：2017/6/13 13:12
 * 作用：跳转工具类
 */

public class IntentUtil {
    /**
     * Activity不传参跳转方法：
     * @param poFram
     * @param poTo
     * @param pbFinish
     */
    public static <T> void gotoActivity(Activity poFram,Class <T>poTo,
           boolean pbFinish){
            Intent loIntent=new Intent(poFram,poTo);
            if(pbFinish)
                poFram.finish();
            poFram.startActivity(loIntent);
    }

    private  static String getCurTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(new Date());
    }

    /**
     * Activity传参跳转方法:
     * @param poFram  当前Activity
     * @param poTo    跳转到的Activity
     * @param pbFinish 跳转后是否关闭之前Activity
     * @param pmExtra Map对象
     */
    public static <T> void gotoActivity(Activity poFram, Class <T>poTo,
           boolean pbFinish, Map<String,String>pmExtra){
        Intent loIntent=new Intent(poFram,poTo);
        if(pmExtra!=null&&!pmExtra.isEmpty()){
            Iterator<String>loKeyIt=pmExtra.keySet().iterator();
            while(loKeyIt.hasNext()){
                String lsKey=loKeyIt.next();
                loIntent.putExtra(lsKey,pmExtra.get(lsKey));
            }
        }
        if(pbFinish)
            poFram.finish();
        poFram.startActivity(loIntent);
    }

    /**
     * Activity传对象的跳转方法
     * @param poFram 当前Activity
     * @param poTo   跳转到的Activity
     * @param t      对象
     */
    public static <T extends Serializable> void gotoActivity(Activity poFram,Class <T>poTo,
                                                             boolean pbFinish, T t){
        Intent intent=new Intent(poFram, poTo);
        intent.putExtra(t.getClass().getSimpleName(),t);
        if(pbFinish)
            poFram.finish();
        poFram.startActivity(intent);
    }


}
